using System;
using System.IO;
using System.Threading.Tasks;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Magicodes.ExporterAndImporter.Pdf;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WkHtmlToPdfDotNet;

namespace Admin.NET.Application.Service;

/// <summary>
/// 自己业务服务
/// </summary>
[ApiDescriptionSettings(new string[] { "业务应用" }, Order = 200)]
[AllowAnonymous]
public class Test2Service : IDynamicApiController, ITransient, IPrivateDependency
{
	/// <summary>
	/// 生成PDF文件
	/// </summary>
	/// <returns></returns>
	public async Task<dynamic> CreatePDFReport()
	{
		string tpl = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "temp/CovidReport.html"));
		PdfExporter exporter = new PdfExporter();
		return new FileStreamResult(new MemoryStream(await exporter.ExportBytesByTemplate(pdfExporterAttribute: new PdfExporterAttribute
		{
			Orientation = Orientation.Portrait,
			PaperKind = PaperKind.A4
		}, data: new ReportData
		{
			Name = "张三",
			IdNo = "130430xxxxxxxxxxxx",
			Sex = "男",
			Age = 35,
			TudeNo = "12345678901",
			CollectTime = "2022-08-01 12:33:33",
			ReceiveTime = "2022-08-01 18:33:33",
			CheckTime = "2022-08-02 18:33:33"
		}, template: tpl)), "application/octet-stream")
		{
			FileDownloadName = "核酸.PDF"
		};
	}
}
